#ifndef _MODEL_LOGIN_LOG_H_
#define _MODEL_LOGIN_LOG_H_

#include <vector>
#include <string>

#include "wx/dataview.h"

#include "data/db_struct.h"

class wxDateTime;
class LoginLogModel : public wxDataViewVirtualListModel
{
public:
    enum
    {
        Col_Account,
        Col_Name,
        Col_Login,
        Col_Logout,
        Col_Online,
        Col_IP,
        Col_Port,
        Col_ServerID,
        Col_Max,
    };

    LoginLogModel();

    virtual unsigned int GetColumnCount() const
    {
        return Col_Max;
    }

    virtual wxString GetColumnType(unsigned int col) const
    {
        switch(col)
        {
            case Col_Account:
                {
                    return wxT("long");
                }
                break;
            case Col_Name:
                {
                    return wxT("string");
                }
                break;
            case Col_Login:
                {
                    return wxT("string");
                }
                break;
            case Col_Logout:
                {
                    return wxT("string");
                }
                break;
            case Col_Online:
                {
                    return wxT("string");
                }
                break;
            case Col_IP:
                {
                    return wxT("string");
                }
                break;
            case Col_Port:
                {
                    return wxT("long");
                }
                break;
            case Col_ServerID:
                {
                    return wxT("long");
                }
                break;
            default:
                {
                    return wxT("long");
                }
        }
    }

    virtual unsigned int GetRowCount()
    {
        return _node_list.size();
    }

    virtual void GetValueByRow(wxVariant& variant, unsigned int row, unsigned int col) const;
    virtual bool GetAttrByRow(unsigned int row, unsigned int col, wxDataViewItemAttr& attr) const;
    virtual bool SetValueByRow(const wxVariant& variant, unsigned int row, unsigned int col);

public:
    bool InsertNode(LoginLogNode* node);
    bool LoadData(const wxDateTime& start_time, const wxDateTime& end_time, const std::wstring& account_name = _T(""));
    void Clear();

private:
//    class Compare
//    {
//    private:
//        unsigned int _col;
//        bool _ascending;
//    public:
//        Compare(unsigned int col, bool ascending):_col(col), _ascending(ascending){}
//        bool operator()(const LoginLogNode& node1, const LoginLogNode& node2) const
//        {
//            bool ret;
//            if (_col == 0)
//                ret = node1.col0 < node2.col0;
//            else if (_col == 1)
//                ret = node1.col1 < node2.col1;
//            else if (_col == 2)
//                ret = node1.col2 < node2.col2;
//            else
//                ret = false;
//            return _ascending ? !ret : ret;
//        }
//    };

public:
//    void Sort(unsigned int col, bool ascending);

private:
    std::vector<LoginLogNode*> _node_list;

};


#endif // _MODEL_LOGIN_LOG_H_
